"""
@File    :   router.py
@Time    :   2024/02/19 08:06:23
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   租户套餐套餐路由
"""

from typing import Annotated

from fastapi import APIRouter, Depends

from src.business.admin.system.oauth2.token.dependencies.no_introduction import (
    DependVerifyAccessTokenMenumPermission,
)
from src.enums.permission_operation import PermissionOperationEnum
from src.utils.unified_response import SuccessApiJSONResponse

from .dependencies.route_depend import (
    route_depend_create_tenant_package,
    route_depend_delete_tenant_package,
    route_depend_get_tenant_package,
    route_depend_list_simple_tenant_package,
    route_depend_list_tenant_package,
    route_depend_update_tenant_package,
    route_depend_update_tenant_package_status,
)
from .schemas.out import (
    TenantPackageAndMenuCompleteOutSchema,
    TenantPackageCompleteOutSchema,
    TenantPackageSimpleOutSchema,
)

# 构建权限验证相关的依赖项
# 查
depend_select_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.select.value
)
# 增
depend_create_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.create.value
)
# 改
depend_update_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.update.value
)
# 删
depend_delete_permission_verify = DependVerifyAccessTokenMenumPermission(
    __file__, PermissionOperationEnum.delete.value
)


# 创建路由
router = APIRouter(
    prefix="/admin/system/tenant/package",
    tags=[
        "后台租户套餐接口",
    ],
)


@router.get("/get", summary="查询单个租户套餐")
async def route_get_tenant_package(
    verify_menu_permission: Annotated[None, Depends(depend_select_permission_verify)],
    tenant_package: Annotated[
        TenantPackageAndMenuCompleteOutSchema, Depends(route_depend_get_tenant_package)
    ],
):
    return SuccessApiJSONResponse(data=tenant_package)


@router.post("/list", summary="查询租户套餐完整信息列表")
async def route_list_tenant_package(
    verify_menu_permission: Annotated[None, Depends(depend_select_permission_verify)],
    list_result: Annotated[
        tuple[list[TenantPackageCompleteOutSchema], int],
        Depends(route_depend_list_tenant_package),
    ],
):
    search_pagination_result, search_total = list_result
    data = {"result": search_pagination_result, "total": search_total}
    return SuccessApiJSONResponse(data=data)


@router.post("/list-simple", summary="查询租户套餐简单信息列表")
async def route_list_simple_tenant_package(
    verify_menu_permission: Annotated[None, Depends(depend_select_permission_verify)],
    list_result: Annotated[
        list[TenantPackageSimpleOutSchema],
        Depends(route_depend_list_simple_tenant_package),
    ],
):
    return SuccessApiJSONResponse(data=list_result)


@router.post("/create", summary="创建租户套餐")
async def route_create_tenant_package(
    verify_menu_permission: Annotated[None, Depends(depend_create_permission_verify)],
    created_id: Annotated[int, Depends(route_depend_create_tenant_package)],
):
    data = {"created_id": created_id}
    return SuccessApiJSONResponse(data=data)


@router.post("/update", summary="修改租户套餐")
async def route_update_tenant_package(
    verify_menu_permission: Annotated[None, Depends(depend_update_permission_verify)],
    update_operation: Annotated[None, Depends(route_depend_update_tenant_package)],
):
    return SuccessApiJSONResponse()


@router.post("/update-status", summary="修改租户套餐状态")
async def route_update_tenant_package_status(
    verify_menu_permission: Annotated[None, Depends(depend_update_permission_verify)],
    update_status_operation: Annotated[
        None, Depends(route_depend_update_tenant_package_status)
    ],
):
    return SuccessApiJSONResponse()


@router.post("/delete", summary="删除租户套餐")
async def route_delete_tenant_package(
    verify_menu_permission: Annotated[None, Depends(depend_delete_permission_verify)],
    delete_operation: Annotated[None, Depends(route_depend_delete_tenant_package)],
):
    return SuccessApiJSONResponse()
